<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="所属灯杆">
              <j-search-select-tag
                placeholder="请选择所属灯杆"
                v-model="queryParam.lightPoleId"
                dict="tb_light_pole,light_name,id"
              />
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="设备名称">
              <a-input placeholder="请输入设备名称" v-model="queryParam.name"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a-button @click="add" type="primary" icon="plus" style="margin-left: 8px">新增</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- table区 -->
    <div>
      <a-table
        ref="table"
        size="middle"
        :scroll="{ x: true }"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        @change="handleTableChange"
      >
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text, record">
          <span v-if="!text" style="font-size: 12px; font-style: italic">无图片</span>
          <img
            v-else
            :src="getImgView(text)"
            :preview="record.id"
            height="25px"
            alt=""
            style="max-width: 80px; font-size: 12px; font-style: italic"
          />
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px; font-style: italic">无文件</span>
          <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="deviceControl(record)">设备控制</a>
          <a-divider type="vertical" />
          <a @click="openProgramListModal(record)">节目</a>
          <a-divider type="vertical" />
          <a @click="handleEdit(record)">详情</a>
          <a-divider type="vertical" />
          <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
            <a>删除</a>
          </a-popconfirm>
        </span>
      </a-table>
    </div>

    <ScreenModal ref="modalForm" @ok="modalFormOk" />
    <DeviceControlModal ref="deviceControlModalRef" @ok="modalFormOk" />
    <ProgramListModal ref="programListModalRef" />
  </a-card>
</template>

<script>
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import ScreenModal from './modules/screenModal.vue'
import DeviceControlModal from './modules/deviceControlModal'
import ProgramListModal from './modules/programListModal'
export default {
  name: 'ScreenList',
  mixins: [JeecgListMixin],
  components: { ScreenModal, DeviceControlModal, ProgramListModal },
  data() {
    return {
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          },
        },
        {
          title: '设备名称',
          align: 'center',
          dataIndex: 'name',
        },
        {
          title: '设备编号',
          align: 'center',
          dataIndex: 'deviceCode',
        },
        {
          title: '设备型号',
          align: 'center',
          dataIndex: 'deviceModel',
        },
        {
          title: '设备类型',
          dataIndex: 'deviceType',
          align: 'center',
          customRender: function (text) {
            const deviceNameMap = {
              1: '照明',
              2: '回路设备',
              3: '工业设备',
              4: '气象',
              5: '摄像头',
              6: 'led屏',
            }
            return deviceNameMap[text]
          },
        },
        {
          title: '在线状态',
          align: 'center',
          dataIndex: 'olStatus',
          customRender: function (text) {
            const olStatusNameMap = { 0: '离线', 1: '在线' }
            return olStatusNameMap[text]
          },
        },
        {
          title: '所属灯杆',
          align: 'center',
          dataIndex: 'lightPoleId_dictText',
        },
        {
          title: '所属分组',
          align: 'center',
          dataIndex: 'groupId_dictText',
        },
        {
          title: '所属项目',
          align: 'center',
          dataIndex: 'projectId_dictText',
        },
        {
          title: '亮度',
          align: 'center',
          dataIndex: 'bri',
        },
        {
          title: '上锁状态',
          align: 'center',
          dataIndex: 'screenlockedstatus',
          customRender: function (text) {
            const screenlockedstatusNameMap = { 0: '未锁定', 1: '锁定' }
            return screenlockedstatusNameMap[text]
          },
        },
        {
          title: '屏幕状态',
          align: 'center',
          dataIndex: 'screenonoffstatus',
          customRender: function (text) {
            const screenonoffstatusNameMap = { 0: '关', 1: '开' }
            return screenonoffstatusNameMap[text]
          },
        },
        {
          title: '设备状态',
          align: 'center',
          dataIndex: 'status',
          customRender: function (text) {
            const statusNameMap = { 0: '禁用', 1: '启用', 2: '报警' }
            return statusNameMap[text]
          },
        },
        {
          title: '音量',
          align: 'center',
          dataIndex: 'volume',
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 147,
          scopedSlots: { customRender: 'action' },
        },
      ],
      url: {
        list: '/corp/led/list',
        delete: '/corp/led/delete',
        // deleteBatch: '/corp/weather/deleteBatch',
        // exportXlsUrl: '/corp/weather/exportXls',
        // importExcelUrl: 'corp/weather/importExcel',
      },
      // dictOptions: {},
      superFieldList: [],
    }
  },
  methods: {
    add() {
      this.$refs.modalForm.add()
      this.$refs.modalForm.title = '新增'
    },
    deviceControl(record) {
      this.$nextTick(() => {
        this.$refs.deviceControlModalRef.init(record)
      })
    },
    // 打开节目列表
    openProgramListModal(record) {
      this.$nextTick(() => {
        this.$refs.programListModalRef.init(record.id)
      })
    }
  },
  created() {},
}
</script>

<style lang="less" scoped>
</style>